﻿{include file="public/header"}
<title>修改密码</title>
</head>
<body>
<div class="page-container">
    <form class="form form-horizontal" id="form" method="post">
        <div class="ch-row ch-info-form">
            <p class="flex1"><span class="c-red">*</span>头像：</p>
            <div class="flex4">
                <div id="uploader-demo">
                    <!--用来存放item-->
                    <div id="fileList" class="uploader-list">
                        <div id="<?php echo uniqid('logo')?>" class="file-item thumbnail">
                            <div onclick="delParent(this)"
                                 style="cursor: pointer;background: url({$Think.DOMAIN_SRC}/static/h-ui/images/del.png) no-repeat;background-size:contain;height: 20px;width: 20px;position: absolute;z-index: 10;right: 5px;"></div>
                            <img style="width: 100px;height: 100px;" src="{$admin.logo}">
                            <input name="logo" type="hidden" value="{$admin.logo}">
                            <div class="info"></div>
                        </div>
                    </div>
                </div>
                <div id="filePicker">选择图片</div>
            </div>
        </div>
        <div id="kl">

        </div>
        <div class="ch-row ch-info-form">
            <p class="flex1">用户名：</p>
            <div class="flex4 ch-row ch-info-form-price">
                <input type="text" name="username" value="{$admin.username}">
            </div>
        </div>
        <input type="hidden" name="admin_id" value="{$admin.admin_id}">

        <?php if(!empty($admin['store_id'])){?>
        <div class="ch-row ch-info-form">
            <p class="flex1">店长：：</p>
            <div class="flex4">
                <select name="store_id" class="chan form-control">

                    {volist name='da1' id='v'}

                    <option value="{$v.store_id}"
                    <?php if($admin['store_id']==$v['store_id']){?> selected="selected" <?php }?>
                    >{$v.store_name}</option>

                    {/volist}
                    <option value="0">全部店铺</option>
                </select>
            </div>
        </div>
        <?php }else{?>
        <div class="ch-row ch-info-form">
            <p class="flex1">店长：</p>
            <div class="flex4">
                <select class="form-control goods_category" name="store_id">
                    <option value="0" selected="selected">请选择店铺</option>
                    {volist name='da1' id='v'}
                    <option value="{$v.store_id}">{$v.store_name}</option>
                    {/volist}
                </select>
            </div>
        </div>
        <?php } ?>
        <div class="ch-row ch-info-form">
            <p class="flex1">所属组：</p>
            <div class="flex4">
                <select class="form-control " name="rule">

                    {volist name='da' id='v' }
                    <option value="{$v.id}"
                    <?php if($das==$v['id']){?> selected="selected" <?php }?>>{$v.role_name}</option>
                    {/volist}
                </select>
            </div>
        </div>
        <div class="ch-row ch-info-form">
            <p class="flex1">渠道：</p>
            <div class="flex4 ch-wrap ch-row">
                {volist name='da2' id='v' key='i'}
                <div class="ch-checkbox" style="margin-right:10px;">
                    <input id="ch-checkbox{$i}" type="checkbox" name="qu[]" value="{$v.id}" <?php if($v['xuan']==1){?>
                    checked="checked" <?php }?>>
                    <label for="ch-checkbox{$i}">{$v.title}</label></div>
                {/volist}
            </div>
        </div>
        <div class="ch-row ch-info-form">
            <p class="flex1">是否隐藏电话：</p>
            <div class="flex4 ch-row ch-info-form-price">
                <select class="form-control" name="hide">
                    <option value="1"
                    <?php if($admin['hide']==1){?> selected="selected"  <?php }?>>是</option>
                    <option value="2"
                    <?php if($admin['hide']==2){?> selected="selected"  <?php }?>>否</option>
                </select>
            </div>
        </div>
        <div class="ch-row ch-info-form">
            <p class="flex1">导出权限：</p>
            <div class="flex4 ch-row ch-info-form-price">
                <select class="form-control" name="export">
                    <option value="1"
                    <?php if($admin['export']==1){?> selected="selected"  <?php }?>>是</option>
                    <option value="0"
                    <?php if($admin['export']==0){?> selected="selected"  <?php }?>>否</option>
                </select>
            </div>
        </div>
        <div class="ch-row ch-info-form">
            <p class="flex1">物业：</p>
            <div class="flex2 ch-wrap ch-row">
                {volist name='da3' id='v' key='i'}
                <div class="ch-checkbox" style="margin-right:10px;">
                    <input id="ch-check{$i}" type="checkbox" name="residential_id[]"
                           value="{$v.group_id}" <?php if($v['xu']==1){?> checked="checked" <?php }?>>
                    <label for="ch-check{$i}">{$v.username}</label></div>
                {/volist}

            </div>
        </div>

        <!--<div class="ch-row ch-info-form cdcd">-->
            <!--<p class="flex1">推客宝用户：</p>-->
            <!--<div class="flex2 ch-row ">-->
                <!--<ul id="treeDemo" class="ztree"></ul>-->
            <!--</div>-->
        <!--</div>-->
        <input type="hidden" name="personal_id" id="personal_id">
        <div class="ch-row ch-info-form">
            <button class="btn btn-primary radius" type="button"><i
                    class="Hui-iconfont">&#xe632;</i> 提交
            </button>
        </div>
    </form>
</div>

{include file="public/footer"}
<script type="text/javascript" src="{$Think.DOMAIN_SRC}/lib/zTree/v3/js/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript">
    ss();
    $('.goods_category').bind("change", function () {
        ss();
    });
    // $(function () {
    //     var settingss = {
    //         data: {
    //             simpleData: {
    //                 enable: true,  //true 、 false 分别表示 使用 、 不使用 简单数据模式
    //                 idKey: "id",   //节点数据中保存唯一标识的属性名称
    //                 pIdKey: "pId",    //节点数据中保存其父节点唯一标识的属性名称
    //                 rootPId: 0  //用于修正根节点父节点数据，即 pIdKey 指定的属性值
    //             },
    //             key: {
    //                 name: "name"  //zTree 节点数据保存节点名称的属性名称  默认值："name"
    //             }
    //         },
    //
    //         view: {
    //             dblClickExpand: true,//双击节点时，是否自动展开父节点的标识
    //             showLine: true,//是否显示节点之间的连线
    //             fontCss: {'color': 'black', 'font-weight': 'bold'},//字体样式函数
    //             selectedMulti: true //设置是否允许同时选中多个节点
    //         },
    //         check: {
    //             chkboxType: {"Y": "ps", "N": "ps"},
    //             // chkboxType: { "Y": "", "N": "" },
    //             chkStyle: "checkbox",//复选框类型
    //             enable: true //每个节点上是否显示 CheckBox
    //         },
    //         callback: {
    //
    //             onClick: function (e, treeId, treeNode, clickFlag) {     //用于捕捉勾选时触发
    //
    //                 zTree.checkNode(treeNode, !treeNode.checked, true);//勾选或取消勾选单个节点
    //
    //             }
    //
    //         }
    //
    //     };
    //     $(document).ready(function () {
    //         $.ajax({
    //             type: "get",
    //             url: "{:Url('index/role/getMenuTestListEdit')}",
    //             async: true,
    //             data: {id:'{$admin.admin_id}'},
    //             success: function (res) {
    //                 var dat=JSON.parse(res);
    //                 console.log(dat);
    //                 $.fn.zTree.init($("#treeDemo"), settingss, dat);
    //                 var treeObj=$.fn.zTree.getZTreeObj("treeDemo");
    //                 for(var i = 0; i < dat.length; i++) {
    //                     var node = treeObj.getNodeByParam("id", dat[i].checked);
    //                     if(node != 0) {
    //                         treeObj.checkNode(node, true);
    //                     }
    //                 }
    //             }
    //         });
    //     });
    // })
    function ss() {
        var parent_ids = $(".goods_category option:selected").val();
        if (parent_ids == 9) {

            var html;
            html = ' <div class="row cl ss">\n' +
                '            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>手机号码：</label>\n' +
                '            <div class="formControls col-xs-8 col-sm-9">\n' +
                '                <input type="text" class="form-control" value="{$admin.mobile}" name="mobile"  style="    width: 30%;">\n' +
                '            </div>\n' +
                '        </div>';
            $("#kl").append(html);
        } else {
            $(".ss").remove();
        }
    }

    $('.radius').click(function () {
        // var treeObj=$.fn.zTree.getZTreeObj("treeDemo");
        // var nodes =  treeObj.getCheckedNodes(true);   //获取被勾选/未勾选的节点集合
        var v="";
        // for(var i=0;i<nodes.length;i++){
        //     v+=nodes[i].id + ",";
        //
        // }
        $('#personal_id').val(v);
        var src = "{:Url('index/role/edit')}";
        $.ajax({
            type: 'POST',
            url: src,
            dataType: 'json',
            data: $('form').serializeArray(),
            success: function (data) {
                var res = JSON.parse(data);
                if (res.code == 200) {
                    layer.msg(res.msg, {icon: 1, time: 2000}, function (index, layero) {
                        parent.location.reload()
                    });
                } else {
                    layer.msg(res.msg, {icon: 5, time: 1000});
                }

            },
            error: function (data) {
                console.log(data.msg);
            },
        });

    });

    function delParent(object) {
        $(object).parent().remove();
        count -= 1;
    }

    var count = 0;
    $(function () {
        var $list = $("#fileList");
        var uploader = WebUploader.create({
            auto: true,
            // swf文件路径

            // 文件接收服务端。
            server: "{:Url('index/upload/upload_file')}",

            // 选择文件的按钮。可选。
            // 内部根据当前运行是创建，可能是input元素，也可能是flash.
            pick: '#filePicker',

            // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
            resize: false,
            duplicate: true,

            accept: {
                title: 'Images',
                extensions: 'gif,jpg,jpeg,bmp,png',
                mimeTypes: 'image/*'
            },
        });

        // 当有文件添加进来的时候
        uploader.on('fileQueued', function (file) {
            var $li = $(
                '<div id="' + file.id + '" class="file-item thumbnail">' +
                '<img style="width: 100px;height: 100px;">' +
                '<input name="logo" type="hidden" value="">' +
                '<div class="info">' + file.name + '</div>' +
                '</div>'
                ),
                $img = $li.find('img');


            // $list为容器jQuery实例
            $list.append($li);

            // 创建缩略图
            // 如果为非图片文件，可以不用调用此方法。
            // thumbnailWidth x thumbnailHeight 为 100 x 100
            uploader.makeThumb(file, function (error, src) {
                if (error) {
                    $img.replaceWith('<span>不能预览</span>');
                    return;
                }

                $img.attr('src', src);
            }, 100, 100);
        });

        uploader.on('beforeFileQueued', function (file) {
            if (count > 0) {
                return false;
            }
            return true;
        });

        // 文件上传过程中创建进度条实时显示。
        uploader.on('uploadProgress', function (file, percentage) {
            var $li = $('#' + file.id),
                $percent = $li.find('.progress span');

            // 避免重复创建
            if (!$percent.length) {
                $percent = $('<p class="progress"><span></span></p>')
                    .appendTo($li)
                    .find('span');
            }


            $percent.css('width', percentage * 100 + '%');
        });

        // 文件上传成功，给item添加成功class, 用样式标记上传成功。
        uploader.on('uploadSuccess', function (file, res) {
            var data = JSON.parse(res._raw);
            if (data.errcode == 300) {
                layer.alert(data.msg);
            }

            var url = data.data;
            $("#fileList").children().first().remove();
            count -= 1;
            $('#' + file.id).find("logo").attr("src", url);
            $('#' + file.id).find("input").val(url);
            $('#' + file.id).addClass('upload-state-done');
        });

        // 文件上传失败，显示上传出错。
        uploader.on('uploadError', function (file) {
            var $li = $('#' + file.id),
                $error = $li.find('div.error');

            // 避免重复创建
            if (!$error.length) {
                $error = $('<div class="error"></div>').appendTo($li);
            }

            $error.text('上传失败');
        });

        // 完成上传完了，成功或者失败，先删除进度条。
        uploader.on('uploadComplete', function (file) {
            $('#' + file.id).find('.progress').remove();
        });
    });
</script>
</body>
</html>
